package com.test.languagetest;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.hibernate.classic.Session;

import com.pojo.Category;
import com.pojo.Product;

public class HibernateTestManyToOne {

	public static void main(String[] args) {
		SessionFactory sf = new Configuration().configure().buildSessionFactory();
		Session session = sf.openSession();
		session.beginTransaction();
		
		Category c = new Category();
		c.setName("手机");
		
		session.save(c);
		
		Product p = (Product) session.get(Product.class, 6);
		p.setCategory(c);
		// 更新
		session.update(p);
		
		
		session.getTransaction().commit();
		session.close();
		sf.close();
	}
}
